package models
{
    import mx.core.FlexGlobals;
    import mx.core.UITextFormat;
    
    public class TextUtils
    {
        public function TextUtils()
        {
        }
        
        public static function measureTextWidth( text:String ,fontSize:int = 16):Number {	
            
            var uiTextFormat:UITextFormat = new UITextFormat(FlexGlobals.topLevelApplication.systemManager);
            
            uiTextFormat.antiAliasType="advanced"; //这两个参数不设置会抛错
            
            uiTextFormat.gridFitType="pixel";
            
            // 不设置字体会计算的不对
            
            uiTextFormat.font="黑体";//默认字体	
            
            uiTextFormat.size= fontSize; //可以设置字体大小
            
            return uiTextFormat.measureText(text).width;
        
        }
    }
}

